	package simpleftp.server;
	
	import java.net.ServerSocket;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
	
	/**
	 * Simple serveur TCP creant des thread pour gerer chaque connexion client.
	 * 
	 * @author lom
	 */
	public class FTPServerMain {
	
		/**
		 * Port d'ecoute.
		 */
		public static final int PORT = 7802;
		private static ExecutorService executorPool = null;
		private static CompletionService<Boolean> completionPool = null;
		private static int numberOfCores = 4;
		private static final double blockingCoefficient = 0.9;
		private static int poolSize = 0;
		/**
		 * Socket serveur d'accueil.
		 */
		private static ServerSocket socketaccueil;
	
		public static void main(String argv[]) throws Exception {
			
			// TO BE COMPLETED - MAKE IT MULTITHREAD - 4  LINES
			numberOfCores = Runtime.getRuntime().availableProcessors();
			poolSize = (int) (numberOfCores / (1 - blockingCoefficient));
			executorPool = Executors.newFixedThreadPool(poolSize);
			//completionPool = new ExecutorCompletionService<Boolean>(executorPool);
			
			
			try {
				socketaccueil = new ServerSocket(PORT);
				System.out.println("Server up and running.");
				FTPServer.setDebug(true);
				while (true) {
					FTPServer server = new FTPServer(socketaccueil.accept());
					/// TO BE COMPLETED - 1 LINE OK
					executorPool.submit(server);
				}
			} finally {
				if (socketaccueil != null) {
					socketaccueil.close();
				}
			}
		}
	}
